

const contents = [
    {
        id: 1,
        img: 'https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/4c241f4cc24b47428403234e68e281b3~tplv-k3u1fbpfcp-watermark.image?',
        text: '2022中国平安足球协会超级联赛(海口赛区)',
        date: '2022.6.25 19:30 周六',
        pos: '北京 五源河体育场',
        price: '100元',
        type: '体育赛事' 
    },
    {
        id: 2,
        img: 'https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0bd814b7e4294a5daaa832204f0ad239~tplv-k3u1fbpfcp-watermark.image?',
        text: '【9.9元超值特惠】马语汇亲子马术活动',
        date: '2022.6.23 19:30 周六',
        pos: '上海 马场',
        price: '9.9元',
        type: '体育赛事' 
    },
    {
        id: 3,
        img: 'https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c3d8df626c4a4851ba4e22a79a4e5ddc~tplv-k3u1fbpfcp-watermark.image?',
        text: '【5折超值特惠】马语汇亲子马术体验活动',
        date: '2022.6.27 19:30 周六',
        pos: '上海 马场',
        price: '996元',
        type: '体育赛事' 
    },
    {
        id: 4,
        img: 'https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/50979dfaead247caa31163edf0e4bd2a~tplv-k3u1fbpfcp-watermark.image?',
        text: '2022英雄联盟夏季赛六六六(中国赛区)',
        date: '2022.6.25 19:30 周六',
        pos: '西安 广场',
        price: '111元',
        type: '电竞赛事' 
    },
    {
        id: 5,
        img: 'https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/805e3db4c8974a3dbfd411bd4183dfc2~tplv-k3u1fbpfcp-watermark.image?',
        text: '2022中国拳王争霸赛(街道赛区)',
        date: '2022.6.25 19:30 周六',
        pos: '北京 街道',
        price: '567元',
        type: '体育赛事' 
    },
    {
        id: 6,
        img: 'https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/048e29e23908497daa7ed34ee8b54d57~tplv-k3u1fbpfcp-watermark.image?',
        text: '2022中国平安足球协会超级联赛(海口赛区)',
        date: '2022.6.25 19:30 周六',
        pos: '西安 五源河体育场',
        price: '888元',
        type: '体育赛事' 
    },
    {
        id: 7,
        img: 'https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/fcd806712ce94deea51daad8abf37863~tplv-k3u1fbpfcp-watermark.image?',
        text: '2023英雄联盟手游春季赛直播(海口赛区)',
        date: '2022.6.25 19:30 周六',
        pos: '北京 五源河体育场',
        price: '234元',
        type: '电竞赛事' 
    },
    {
        id: 8,
        img: 'https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/7038eda29e2345579a46d7667c5c37bc~tplv-k3u1fbpfcp-watermark.image?',
        text: '2023英雄联盟世界赛(北京赛区)~~~',
        date: '2023.7.17 17:37 周六',
        pos: '北京 体育场',
        price: '999元',
        type: '电竞赛事' 
    },   
]
// withDelay(function () {})  return async函数
// delay函数
const delay = time => new Promise(resolve => setTimeout(resolve, time));
const withDelay = fn => async (...args) => {
    await delay(1000);
    return fn(...args)
}

export const fetchcontents = withDelay(params => {
    const { inputContent, activeKey, city='' } = params
    let result = contents;
    if (activeKey) {
        switch (activeKey) {
            case "电竞赛事":
                result = result.filter(content => content.type === '电竞赛事')
                break;
            case "体育赛事":
                result = result.filter(content => content.type === '体育赛事')
                break;
            default:
                break
        }
    }
    if (inputContent) {
        result = result.filter(content => (
            content.text+content.date+content.price+content.pos).includes(inputContent))
    }
    if (city && city !== '所有城市'&& city !== '城市') {
        result = result.filter(content => content.pos.includes(city))
    }

    return Promise.resolve({
        activeKey, result
    })
})

    // Promise 类 resolve 静态方法
    // Promise.all 返回以一个fullfiled的promise实例
    // 一般用于返回promise实例